﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jzy.BLL.HR;
using Jzy.Model;
using System.IO;
using Jzy.Model.HR;
using Frame.Lib.Common;
using Frame.Lib.Utilities;
using Frame.Lib.Core.Attach;


public partial class HumanResource_Employee_MyInfo : PageEdit
{
    private EmployeeBO employee = new EmployeeBO();

    private string _empID;
    private string EmployeeID
    {
        get
        {
            if (_empID == null)
            {
                _empID = AppSession.UserID.ToString();
            }
            return _empID;
        }
    }

   
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {            
            DispInfo();
        }        
    }

    private void DispInfo()
    {
        EmployeeInfo info = employee.GetInfo(EmployeeID);
        if (info != null)
        {
            EntityUtil.SetControl(pnlMain, info);
            imgPhotoUrl.ImageUrl = info.PhotoAbsPath;
            txtCode.Text = info.Code;
        }
      

        txtName.Text = AppSession.UserName;
        DeptName.Text = AppSession.DeptName;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        EmployeeInfo info = employee.GetInfo(EmployeeID);

        bool isAdd = (info == null);
        info = info ?? new EmployeeInfo();
        

        info.ID = AppSession.UserID;
        info.Name = AppSession.UserName;

        if (isAdd)
        {
            info.Status = (int)EmployeeStatus.在职;
            info.InputTime = DateTime.Now;
            info.AllowEdit = true;
        }

        EntityUtil.SetEntity(pnlMain, info);

        if (filPhoto.PostedFile.ContentLength > 0)
        {
            string strFileExtension = System.IO.Path.GetExtension(filPhoto.PostedFile.FileName).ToLower();
            if (strFileExtension != ".gif" && strFileExtension != ".jpg")
            {
                JSUtil.Alert("图片格式不对！");
                return;
            }

            UserImage userImage = new UserImage("Employee");
            if (string.IsNullOrEmpty(info.Photo))
            {
                info.Photo = userImage.Save(filPhoto.PostedFile, 100, 140);
            }
            else
            {
                userImage.Save(filPhoto.PostedFile, 100, 140, info.Photo);
            }
            
        }

        employee.Save(info, isAdd);
        DispInfo();
        JSUtil.Alert("提交成功");
    }
}
